<?php
    session_cache_limiter('private,must-revalide');    
    include_once("../config.php");
    $id= $_POST['id'];	
	$cate_id = intval( $_POST["cate_id"] ); //分类
	//date_default_timezone_set('Asia/Shanghai');	
	$time=date('Y-m-d H:i:s');
    $name =$_POST["name"];		//中文标题
	$admin =$_POST["admin"];		//中文标题
	$search = "SELECT * FROM $TBL_HOUSE WHERE (cate_id='$cate_id' AND name='$name' and id!=$id) or (cate_id='$cate_id' AND admin='$admin' and id!=$id)";
	$result = mysql_query( $search );
	if( @mysql_num_rows( $result ) > 0 )
	{
		MyNotice("以该标题命名的农家乐或此管理员已存在,请换个试试!");
		exit();
	}
   	$text = work_str($_POST["chinese_edit"], 1);					
	$tel = work_str($_POST["tel"], 1);			
	$price = work_str($_POST["price"], 1);	
	$bed = work_str($_POST["bed"], 1);	
	$cbiao = work_str($_POST["cbiao"], 1);	
	$line = work_str($_POST["line"], 1);
	$cp = work_str($_POST["cp"], 1);
	$cont1 = array("<p>","</p>");
	$cont2 = array("","</br>");
	$text1 = str_replace($cont1, $cont2, $text);	
	$user_id = $_SESSION['user_id'];
	$img = $_FILES['img']['name'];
	if($img=='')
	{
		$query = "UPDATE $TBL_HOUSE SET cate_id='$cate_id',
		name='$name',text='$text1', tel='$tel',line='$line',
		price='$price',cbiao='$cbiao',bed='$bed',
		date_added='$time',user_id='$user_id',admin='$admin' where id=$id";	
	}else{
		$query = "UPDATE $TBL_HOUSE SET cate_id='$cate_id',
		name='$name',text='$text1',tel='$tel',line='$line',
		price='$price',cbiao='$cbiao',bed='$bed',
		date_added='$time',user_id='$user_id',img='$img',admin='$admin' where id=$id";	
	}
	if($cp==1)
	{
		$password = md5($_POST['password']);
		$qur= "UPDATE $TBL_HOUSE SET password='$password' where id=$id";	
		mysql_query($qur) or die(mysql_error());	
	}
	$res = mysql_query($query) or die(mysql_error());	
	$insert_id = $id;	
	if($_FILES['img']['name']!='')
	{		
		@mkdir($conf['fck_upload'] . "hflinfo/".$insert_id);
		@chmod($conf['fck_upload'] . "hflinfo/".$insert_id,0777);		
		$img_file =$conf['fck_upload'] . "hflinfo/".$insert_id;
		$file_full = $img_file."/".$img;
		$upload_file = $_FILES['img']['tmp_name'];          //上传过来的压缩文件
		@move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹		
	}
	/*if($_FILES['bigimg']['name']!='')
	{		
		@mkdir($conf['fck_upload'] . "pros/".$insert_id);
		@chmod($conf['fck_upload'] . "pros/".$insert_id,0777);
		$img_file2 =$conf['fck_upload'] . "pros/".$insert_id;
		$file_full2 = $img_file2."/".$bigimg;
		$upload_file2 = $_FILES['bigimg']['tmp_name'];          //上传过来的压缩文件
		move_uploaded_file($upload_file2, $file_full2);       //上传到指定文件夹		
	}

	for($i=0; $i<count($_FILES['upfile']['name']); $i++) 
	{       				  
		$name = $_FILES['upfile']['name'][$i];
		if($name!='')
		{
			@mkdir($conf['fck_upload'] . "pros/".$insert_id);
			@chmod($conf['fck_upload'] . "pros/".$insert_id,0777);
			$save_file = $conf['fck_upload'] . "pros/".$insert_id;   //存上传文件的文件夹
			$save_path = $save_file;			
			$file_name = $name;	
			$file_full = $save_path .'/'. $file_name; 
			$upload_file = $_FILES['upfile']['tmp_name'][$i]; //上传过来的压缩文件
			move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹
			chmod($file_full,0777);
			$query1="INSERT INTO $TBL_PIC SET NEW_ID='$insert_id',name='$name',type=1,IMG_NAME='$file_name',REG_TIME='$time'";
			$result1 = mysql_query($query1) or die(mysql_error());
		}
	 
	}*/
		 MyNotice("农家乐信息修改成功", 2, "../news.php");
		 exit(0);  
  
?>